package com.caesar.Date.convert_each;

import org.junit.jupiter.api.Test;

import java.time.*;
import java.util.Date;

/**
 * @author caesar
 * @date 2025/7/15
 * @Description:第1代与第3代之间的转换
 * @apiNote
 */
public class TestOneThree {
    @Test
    public void test1(){
        Date d = new Date();
        Instant instant = d.toInstant();//第1代->第3代
        LocalDateTime ldt = LocalDateTime.ofInstant(instant, ZoneId.of("Asia/Shanghai"));
        System.out.println(ldt);
        //2025-07-15T10:12:03.075
    }

    @Test
    public void test2(){
        LocalDateTime ldt = LocalDateTime.now();
        ZonedDateTime zonedDateTime = ldt.atZone(ZoneId.of("Asia/Shanghai"));//通过时区id创建时区
        Instant instant = zonedDateTime.toInstant();
        Date date = Date.from(instant);
        System.out.println(date);
        //Tue Jul 15 10:13:55 CST 2025
    }

    @Test
    public void test3(){
        LocalDateTime ldt = LocalDateTime.now();
        Instant instant = ldt.toInstant(ZoneOffset.of("+08:00"));//东八区，偏移8个小时的时区
        Date date = Date.from(instant);
        System.out.println(date);
        //Tue Jul 15 10:15:49 CST 2025
    }
}
